home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
bbs
/
twall62s.zip
/
input.mh
< prev
next >
Wrap
Text File
|
1996-07-28
|
2KB
|
108 lines
#ifndef __XGETCH_MH
#include <xgetch.mh>
#endif
#ifndef __INPUT_MH
#define __INPUT_MH
#endif
void cutchar(ref string: line, int: index);
void putchar(ref string: line, int: index, char: ch);
void inputstring(ref string: line, int: maxlen);
void cutchar(ref string: line, int: index)
{
string: outline;
outline:=substr(line,1,index-1)+substr(line,index+1,(strlen(line)-index));
line:=outline;
}
void putchar(ref string: line, int: index, char: ch)
{
string: outline;
outline:=substr(line,1,index-1);
outline[strlen(outline)+1]:=ch;
outline:=outline+substr(line,index,(strlen(line)-index+1));
line:=outline;
}
void inputstring(ref string: line, int: maxlen)
{
char: ch;
int: pos, len, tmp;
start:;
if (line<>"") print(line);
len:=strlen(line);
pos:=len+1;
do
{
ch:=xgetch(); // get character from keyboard
if (ch=8) // if character is backspace print it
{
if (pos>1)
{
print("\b \b");
tmp:=sys.current_col;
print(substr(line, pos, len-pos+1)+" ");
print(AVATAR_GOTO, (char)sys.current_row, (char)tmp);
pos:=pos-1;
len:=len-1;
cutchar(line,pos);
}
}
else if (ch=0)
{
ch:=xgetch();
if (ch=X_LEFT AND pos>1) // left
{
pos:=pos-1;
print(AVATAR_LEFT);
}
else if (ch=X_RIGHT AND pos<=len) // right
{
pos:=pos+1;
print(AVATAR_RIGHT);
}
else if (ch=X_HOME AND pos>1) // home
{
print(AVATAR_GOTO, (char)sys.current_row,
(char)(sys.current_col-pos+1));
pos:=1;
}
else if (ch=X_END AND pos<=len) // end
{
print(AVATAR_GOTO, (char)sys.current_row,
(char)(sys.current_col+(len-pos+1)));
pos:=len+1;
}
else if (ch=X_DELETE AND pos<=len) // del
{
cutchar(line,pos);
len:=len-1;
tmp:=sys.current_col;
print(substr(line,pos,(len-pos+1))+" ");
print(AVATAR_GOTO, (char)sys.current_row, (char)tmp);
}
}
else if (ch=13 OR ch=27) print();
else
{
if (len<maxlen)
{
tmp:=sys.current_col;
print(ch);
print(substr(line, pos, len-pos+1));
print(AVATAR_GOTO, (char)sys.current_row, (char)(tmp+1));
putchar(line,pos,ch);
pos:=pos+1;
len:=len+1;
}
}
}
while (ch<>13);
}